home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 281 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.9 KB

  1. Path: kbad.eglin.af.mil!rpi!not-for-mail
  2. From: kanze@gabi-soft.fr (J. Kanze)
  3. Newsgroups: comp.lang.c++.moderated,comp.lang.c++
  4. Subject: Re: Meaning of the specifier volatile?
  5. Followup-To: comp.lang.c++.moderated,comp.lang.c++
  6. Date: 3 Jan 1996 14:54:16 -0000
  7. Organization: GABI Software, Sarl.
  8. Sender: cppmods@netlab.cs.rpi.edu
  9. Approved: Dietmar.Kuehl@uni-konstanz.de
  10. Message-ID: <4ce5ao$ds3@netlab.cs.rpi.edu>
  11. References: <4c9740$27n@netlab.cs.rpi.edu>
  12. NNTP-Posting-Host: netlab.cs.rpi.edu
  13.  
  14. X-Original-Date: 3 Jan 1996 10:27:41 +0100
  15.  
  16. Srinivas Vobilisetti (srv@cs.wayne.edu) wrote:
  17.  
  18. |> I referred to various books on C++ including The C++ Programming Language
  19. |> -Bjarne Stroustrup, C++ Primer -Stanley Lipmann, etc.  Nowhere i could find
  20. |> exact meaning of the specifier volatile. Thanks in advance for your help. I
  21. |> would appreciate the reply at my email address srv@cs.wayne.edu
  22.  
  23. According to the ARM, volatile has no portable meaning; the precise
  24. meaning is implementation defined.  In fact, there are a few odd
  25. guarantees in the standard: in particular, reads and writes of a
  26. volatile are considered part of the observable behavior of a program.
  27. There is also a statement to the effect that the value of a volatile
  28. object may change in ways unknown to the compiler.
  29.  
  30. What this means in practice is that the compiler should turn off
  31. optimization of volatile variables; the program should do exactly what
  32. you wrote, no more, no less.  Note that there is no such guarantee with
  33. regards to other variables; the only guarantee is that the observable
  34. behavior be "as if" the program does what you wrote.
  35.  
  36. Volatile variables are normally used precisely where things are going on
  37. "outside of the program".  The classical example is a (memory-mapped)
  38. real time clock; if the variable were not declared volatile, a good
  39. compiler might detect that it was never written, and save the first
  40. value read somewhere in a register.  Declared volatile, the compiler
  41. must read it every time you write an expression which accesses it.
  42.  
  43. What this means exactly *IS* somewhat implementation dependant.  When
  44. using volatile objects, you should generally eschew complex expressions,
  45. particularly those which access the object twice in the same expression,
  46. and read the documentation for your implementation very carefully, as to
  47. how volatile is interpreted exactly.
  48. -- 
  49. James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
  50. GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
  51. Conseils, itudes et rialisations en logiciel orienti objet --
  52.               -- A la recherche d'une activiti dans une region francophone
  53.  
  54.     [ comp.lang.c++.moderated is a moderated newsgroup.  Submit articles ]
  55.     [  to <c++-submit@netlab.cs.rpi.edu>.  The moderation policy can be  ]
  56.     [   retrieved from <http://netlab.cs.rpi.edu/~cppmods/guide.html>.   ]
  57.     [    Moderators can be reached at: c++-request@netlab.cs.rpi.edu.    ]
  58.